package com.yaojiaxun.logisticsPlatformSystem.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yaojiaxun.logisticsPlatformSystem.entity.MaterialInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @Auther: yjx_j
 * @Date: 2019/1/21 10:40
 * @Description:
 */
@Mapper
public interface MaterialInfoMapper extends BaseMapper<MaterialInfo> {
    @Insert("insert into material_info(material_id, material_type, material_name, suitable_car, suit_car_length, packing_type, single_price, weight, capacity, company,contact_person,contact_phone, resource_area_province," +
            "resource_area_city,resource_area_country, destination_area_province,destination_area_city,destination_area_country," +
            "create_time, update_time) values(#{materialInfo.materialId}, #{materialInfo.materialType}, #{materialInfo.materialName}, #{materialInfo.suitableCar}," +
            " #{materialInfo.suitCarLength}, #{materialInfo.packingType}, #{materialInfo.singlePrice}, #{materialInfo.weight}, #{materialInfo.capacity}, #{materialInfo.company}," +
            "#{materialInfo.contactPerson},#{materialInfo.contactPhone},#{materialInfo.resourceAreaProvince},#{materialInfo.resourceAreaCity},#{materialInfo.resourceAreaCountry},#{materialInfo.destinationAreaProvince}," +
            "#{materialInfo.destinationAreaCity},#{materialInfo.destinationAreaCountry}, #{materialInfo.createTime}, #{materialInfo.updateTime})")
    public void insertMaterialInfo(@Param("materialInfo") MaterialInfo materialInfo);

    @Select("select * from material_info where material_id=#{materialId}")
    public MaterialInfo selectMaterialById(@Param("materialId") Long materialId);

    @Update("update material_info set material_type=#{materialType}, material_name=#{materialName}, suitable_car=#{suitableCar}, suit_car_length=#{suitCarLength}, " +
            "packing_type=#{packingType}, single_price=#{singlePrice}, weight=#{weight}, capacity=#{capacity}, company=#{company},contact_person=#{contactPerson},contact_phone=#{contactPhone},resource_area_province=#{resourceAreaProvince}," +
            "resource_area_city=#{resourceAreaCity},resource_area_country=#{resourceAreaCountry},destination_area_province=#{destinationAreaProvince},destination_area_city=#{destinationAreaCity}," +
            "destination_area_country=#{destinationAreaCountry} where material_id=#{materialId}")
    public Integer updateMaterialByMaterialId(@RequestParam("materialInfo") MaterialInfo materialInfo);

    @Delete("delete from material_info where material_id=#{materialId}")
    public void deleteMaterialById(@Param("materialId") Long materialId);

    @Select("select * from material_info where company=#{company}")
    public List<MaterialInfo> findMaterialByCompany(@Param("company") String company);

    @Select("select * from material_info where material_name=#{materialName}")
    public List<MaterialInfo> findMaterialByMaterialName(@Param("materialName") String materialName);

    //取出后6条数据
    @Select("select * from material_info order by material_id desc limit 6")
    public List<MaterialInfo> findLast6Material();
}
